<template>
  <CompOperate
    :field="field"
    :designer="designer"
    :design-state="designState"
    :parent-list="parentList"
    :parent-widget="parentWidget"
    :sub-form-row-id="subFormRowId"
    :sub-form-row-index="subFormRowIndex"
    :sub-form-col-index="subFormColIndex"
    :index-of-parent-list="indexOfParentList"
    :display-style="field.options.displayStyle"
  >
    <div class="scene-waiting-current-waiting" :style="getStyle('area')">
      <div class="dept-wrp" :key="widgetKey" :style="getStyle('deptWrp')">
        <template v-for="first in doctorPatientList">
          <div class="dept-item" :style="getStyle('deptItem')">
            <template v-for="child in first">
              <div class="dept-con" :style="getStyle('deptCon')">
                <div
                  class="top-wrp"
                  :style="getStyle('topWrp')"
                  :key="widgetKey"
                >
                  <div class="dept-room-name" :style="getStyle('roomNumber')">
                    <ScrollX>
                      {{ child.treatmentRoomName || "\u00a0" }}
                    </ScrollX>
                  </div>
                  <div
                    class="workerName dept-room-name"
                    :style="getStyle('doctorName')"
                  >
                    <ScrollX>
                      {{ child?.deptName }}&nbsp;{{ child?.workerName }}
                    </ScrollX>
                  </div>
                </div>
                <div class="ing-wrp" :style="getStyle('ingWrp')">
                  <div class="ing-label" :style="getStyle('ingLabel')">
                    就诊
                  </div>
                  <div class="ing-con" :style="getStyle('ingCon')">
                    <div
                      v-for="(son, index) in treatingPatientInfo(child)"
                      :key="`current_${widgetKey}_${index}`"
                      :style="getStyle('currentPatient')"
                    >
                      <ScrollX>
                        {{ son.orderNo }}&nbsp;{{ son.patientName }}
                      </ScrollX>
                    </div>
                  </div>
                </div>
                <div class="wait-wrp" :style="getStyle('waitWrp')">
                  <div class="wait-label" :style="getStyle('waitLabel')">
                    待诊
                  </div>
                  <div class="wait-icon" :style="getStyle('waitCon')">
                    <div
                      class="patient-item"
                      v-for="(son, index) in waitingChunkInfos(child)"
                      :key="`wait_${widgetKey}_${index}`"
                      :style="getStyle('waitPatient')"
                    >
                      <ScrollX>
                        {{ son.orderNo }}&nbsp;{{ son.patientName }}
                      </ScrollX>
                    </div>
                  </div>
                </div>
              </div>
            </template>
          </div>
        </template>
      </div>
    </div>
  </CompOperate>
</template>

<script>
import { v4 as uuid } from "uuid";
import { pxToVw } from "@/utils/common";
import emitter from "@/utils/designer/emitter";
import ScrollX from "@c/public/seamlessScroll/ScrollX.vue";
import CompOperate from "@c/public/form-designer/devType/modules/compOperate.vue";
import mixin from "@sc/templateDetails/modules/homeMiddle/fieldMixin";
import { buildParentApi } from "@/utils/designer/util";
import vueSeamlessScroll from "vue-seamless-scroll";

let buildParent = buildParentApi();
export default {
  name: "scene-waiting-more-2columns-dept-widget",

  componentName: "FieldWidget", //必须固定为FieldWidget，用于接收父级组件的broadcast事件

  mixins: [emitter, mixin],

  components: {
    CompOperate,
    ScrollX,
    vueSeamlessScroll,
  },

  props: {
    widget: Object,
    field: Object,
    parentWidget: Object,
    parentList: Array,
    indexOfParentList: Number,
    designer: Object,
    designState: {
      type: Boolean,
      default: false,
    },
    devType: {
      type: Boolean,
      default: false,
    },
    subFormRowIndex: {
      /* 子表单组件行索引，从0开始计数 */ type: Number,
      default: -1,
    },
    subFormColIndex: {
      /* 子表单组件列索引，从0开始计数 */ type: Number,
      default: -1,
    },
    subFormRowId: {
      /* 子表单组件行Id，唯一id且不可变 */ type: String,
      default: "",
    },

    headTitle: {
      type: String,
      default: "",
    },
    visibleTitle: {
      type: Boolean,
    },
  },

  data() {
    return {
      week: "",
      widgetKey: "",
      mockOpen: false,
      waitPatientList: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
    };
  },

  computed: {
    //生成唯一的字符串
    getOnlyId() {
      return function () {
        return uuid();
      };
    },

    classOptionTips() {
      let { scrollableNumber } = this.optionsInfo;
      return {
        step: [1, 1.5, 2, 2.5, 3][0], // 数值越大速度滚动越快
        hoverStop: true,
        limitMoveNum: scrollableNumber, // 开始无缝滚动的数据量 this.dataList.length
        direction: 2, // 0向下 1向上 2向左 3向右
      };
    },

    // 设置的行内样式
    getStyle() {
      return function (val) {
        const self = this;
        let info = self.optionsInfo || Array();
        let Obj = Object();
        switch (val) {
          case "area":
            Reflect.set(Obj, "width", "100%");
            Reflect.set(Obj, "height", pxToVw(info.areaHeight));
            Reflect.set(Obj, "padding", pxToVw(30));
            return Obj;
          case "deptWrp":
            Reflect.set(Obj, "width", "100%");
            Reflect.set(Obj, "height", pxToVw(info.areaHeight));
            return Obj;
          case "deptCon":
            Reflect.set(Obj, "borderRadius", pxToVw(info.deptRadius));
            return Obj;
          case "deptItem":
            Reflect.set(Obj, "marginBottom", pxToVw(20));
            return Obj;
          case "topWrp":
            Reflect.set(
              Obj,
              "color",
              info.topWrpFontColor ? info.topWrpFontColor : "#FFFFFF"
            );

            Reflect.set(
              Obj,
              "background",
              info.topWrpBg ? info.topWrpBg : "#203864"
            );
            Reflect.set(Obj, "height", pxToVw(info.topWrpHeight));
            Reflect.set(Obj, "lineHeight", pxToVw(info.currentFontSize + 20));
            return Obj;
          case "ingWrp":
            Reflect.set(Obj, "height", pxToVw(info.ingHeight));
            Reflect.set(
              Obj,
              "background",
              info.ingConBg ? info.ingConBg : "#FAEDDB"
            );
            return Obj;
          case "ingLabel":
            Reflect.set(Obj, "background", info.ingBg);
            Reflect.set(
              Obj,
              "color",
              info.ingFontColor ? info.ingFontColor : "#ffffff"
            );
            return Obj;
          case "ingCon":
            Reflect.set(Obj, "flex", "1");
            Reflect.set(
              Obj,
              "color",
              info.ingConTextColor ? info.ingConTextColor : "#333333"
            );
            return Obj;

          case "waitWrp":
            Reflect.set(Obj, "height", pxToVw(info.waitHeight));
            Reflect.set(
              Obj,
              "background",
              info.waitConBg ? info.waitConBg : "#ffffff"
            );
            return Obj;
          case "waitLabel":
            Reflect.set(Obj, "background", info.waitBg);
            Reflect.set(
              Obj,
              "color",
              info.waitFontColor ? info.waitFontColor : "#ffffff"
            );
            return Obj;
          case "waitCon":
            Reflect.set(Obj, "flex", "1");
            Reflect.set(
              Obj,
              "color",
              info.waitConTextColor ? info.waitConTextColor : "#333333"
            );
            return Obj;
          case "doctorName":
            Reflect.set(Obj, "fontSize", pxToVw(info.doctorNameFontSize));
            Reflect.set(Obj, "lineHeight", 1.5);
            return Obj;
          case "roomNumber":
            Reflect.set(Obj, "fontSize", pxToVw(info.rommNumberFontSize));
            Reflect.set(Obj, "lineHeight", 1.5);
            return Obj;
          case "currentPatient":
            Reflect.set(Obj, "fontSize", pxToVw(info.currentFontSize || 50));
            return Obj;
          case "waitPatient":
            Reflect.set(Obj, "fontSize", pxToVw(info.waitingFontSize || 50));
            return Obj;
        }
      };
    },

    //  队列-患者-数据
    doctorPatientList() {
      debugger
      let mergeInfo;
      let devType = this.devType;
      let WaitingPatientList =
        this.$store.getters["getWaitingDeptsPatientsInfo"];
      let data = devType
        ? WaitingPatientList.apiData
        : WaitingPatientList.mockData;
      if (data && !!data.length) {
        if (data.length >= 6) {
          mergeInfo = data.slice(0, 6);
        } else {
          let fillArr = new Array(6 - data?.length).fill({
            waitPatientList: [],
          });
          mergeInfo = [...data, ...fillArr];
        }
      } else {
        let fillArr = new Array(6).fill({
          waitPatientList: [],
        });
        mergeInfo = [...fillArr];
      }
      // console.log(this.$lodash.chunk(mergeInfo, 2),mergeInfo,'mergeInfo')
      return this.$lodash.chunk(mergeInfo, 2);
    },

    // 当前就诊患者
    treatingPatientInfo() {
      return function (info) {
        if (!!info.treatingPatient && !!info.treatingPatient.length) {
          return info.treatingPatient.slice(0, 1);
        } else {
          return [];
        }
      };
    },

    // 切割候诊患者
    waitingChunkInfos() {
      return function (info) {
        if (!!info.waitPatientList && !!info.waitPatientList.length) {
          return info.waitPatientList.slice(0, 2);
        } else {
          return [];
        }
      };
    },
  },

  created() {
    this.registerToRefList();
    this.initEventHandler();
    this.handleOnCreated();
  },

  mounted() {
    this.handleOnMounted();
    let info = [
      {
        workerId: "11_0_0",
        workStationId: 11,
        workStationIp: "192.168.116.2",
        workStationName: "192.168.116.2",
        callConfigType: "0",
        workStationIdList: [11],
        registerObjIdList: [3287, 3289],
        registerObjTypeName: "专家号,普通号",
        registerObjNames: "特需-专1,病理性近视专病门诊(曹曼婧)",
        registerObjName: "特需-专1,病理性近视专病门诊(曹曼婧)",
        registerObjSimpleName: "",
        registerObjGroupName: "",
        registerObjGroupSimpleName: "",
        workerName: "专1",
        deptName: "特需门诊,病理性近视专病门诊(曹曼婧)",
        deptShortName: "",
        treatmentRoomName: "特需门诊诊室11111122222223",
        treatmentRoomShortName: "",
        treatmentRoomNumber: "",
        onlineStatus: "0",
        treatingPatient: [
          {
            bookId: null,
            queuingId: "1898595852652408833",
            deptName: "特需门诊",
            orderNo: "过1230-001",
            orderPrefix: "过",
            orderNumber: "1230-001",
            orderTag: "11",
            orderTagColor: "",
            colorPrefix: null,
            ftColor: null,
            bgColor: null,
            patientName: "王*一",
            patientCardNo: null,
            patientIdNo: "9001",
            patientShowNo: null,
            treatType: "0",
            treatStatus: null,
            registerObjName: "特需-专1",
            registerObjId: null,
            registerObjSimpleName: "",
            registerObjGroupName: "特需-专1",
            registerObjGroupSimpleName: "",
            workerStationId: 11,
            treatmentRoomName: null,
            treatmentRoomShortName: null,
            deptCode: null,
            doctorCode: null,
            doctorName: null,
          },
        ],
        waitPatientList: [
          {
            bookId: null,
            queuingId: "1898595852895678465",
            deptName: "特需门诊",
            orderNo: "过1230-001",
            orderPrefix: "过",
            orderNumber: "1230-001",
            orderTag: "11",
            orderTagColor: "",
            colorPrefix: null,
            ftColor: null,
            bgColor: null,
            patientName: "王*二",
            patientCardNo: null,
            patientIdNo: "9002",
            patientShowNo: null,
            treatType: "0",
            treatStatus: null,
            registerObjName: "特需-专1",
            registerObjId: null,
            registerObjSimpleName: "",
            registerObjGroupName: "特需-专1",
            registerObjGroupSimpleName: "",
            workerStationId: 11,
            treatmentRoomName: null,
            treatmentRoomShortName: null,
            deptCode: null,
            doctorCode: null,
            doctorName: null,
          },
          {
            bookId: null,
            queuingId: "1898595894373150722",
            deptName: "特需门诊",
            orderNo: "过1230-003",
            orderPrefix: "过",
            orderNumber: "1230-003",
            orderTag: "11",
            orderTagColor: "",
            colorPrefix: null,
            ftColor: null,
            bgColor: null,
            patientName: "王*三",
            patientCardNo: null,
            patientIdNo: "9003",
            patientShowNo: null,
            treatType: "0",
            treatStatus: null,
            registerObjName: "特需-专1",
            registerObjId: null,
            registerObjSimpleName: "",
            registerObjGroupName: "特需-专1",
            registerObjGroupSimpleName: "",
            workerStationId: 11,
            treatmentRoomName: null,
            treatmentRoomShortName: null,
            deptCode: null,
            doctorCode: null,
            doctorName: null,
          },
        ],
        overPatientList: null,
        waitPatientCount: 4,
        bindType: "2",
      },
      {
        workerId: "12_0_0",
        workStationId: 12,
        workStationIp: "192.168.116.3",
        workStationName: "192.168.116.3",
        callConfigType: "0",
        workStationIdList: [12],
        registerObjIdList: [3288],
        registerObjTypeName: "普通号",
        registerObjNames: "特需-普号",
        registerObjName: "特需-普号",
        registerObjSimpleName: "",
        registerObjGroupName: "",
        registerObjGroupSimpleName: "",
        workerName: "普1",
        deptName: "特需门诊",
        deptShortName: "",
        treatmentRoomName: "2",
        treatmentRoomShortName: "",
        treatmentRoomNumber: "",
        onlineStatus: "0",
        treatingPatient: [
          {
            bookId: null,
            queuingId: "1898648952679460865",
            deptName: "特需门诊",
            orderNo: "1630-001",
            orderPrefix: "",
            orderNumber: "1630-001",
            orderTag: "0",
            orderTagColor: "#C44C4C",
            colorPrefix: null,
            ftColor: null,
            bgColor: null,
            patientName: "王*一",
            patientCardNo: null,
            patientIdNo: "101001",
            patientShowNo: null,
            treatType: "0",
            treatStatus: null,
            registerObjName: "特需-普号",
            registerObjId: null,
            registerObjSimpleName: "",
            registerObjGroupName: "特需-普号",
            registerObjGroupSimpleName: "",
            workerStationId: 12,
            treatmentRoomName: null,
            treatmentRoomShortName: null,
            deptCode: null,
            doctorCode: null,
            doctorName: null,
          },
        ],
        waitPatientList: [
          {
            bookId: null,
            queuingId: "1898648994278567938",
            deptName: "特需门诊",
            orderNo: "1630-002",
            orderPrefix: "",
            orderNumber: "1630-002",
            orderTag: "0",
            orderTagColor: "#C44C4C",
            colorPrefix: null,
            ftColor: null,
            bgColor: null,
            patientName: "王*二",
            patientCardNo: null,
            patientIdNo: "101002",
            patientShowNo: null,
            treatType: "0",
            treatStatus: null,
            registerObjName: "特需-普号",
            registerObjId: null,
            registerObjSimpleName: "",
            registerObjGroupName: "特需-普号",
            registerObjGroupSimpleName: "",
            workerStationId: 12,
            treatmentRoomName: null,
            treatmentRoomShortName: null,
            deptCode: null,
            doctorCode: null,
            doctorName: null,
          },
          {
            bookId: null,
            queuingId: "1898649036099973121",
            deptName: "特需门诊",
            orderNo: "1630-003",
            orderPrefix: "",
            orderNumber: "1630-003",
            orderTag: "0",
            orderTagColor: "#C44C4C",
            colorPrefix: null,
            ftColor: null,
            bgColor: null,
            patientName: "王*三",
            patientCardNo: null,
            patientIdNo: "101003",
            patientShowNo: null,
            treatType: "0",
            treatStatus: null,
            registerObjName: "特需-普号",
            registerObjId: null,
            registerObjSimpleName: "",
            registerObjGroupName: "特需-普号",
            registerObjGroupSimpleName: "",
            workerStationId: 12,
            treatmentRoomName: null,
            treatmentRoomShortName: null,
            deptCode: null,
            doctorCode: null,
            doctorName: null,
          },
        ],
        overPatientList: null,
        waitPatientCount: 5,
        bindType: "2",
      },
    ];
    // doctorPatientList
    console.log(this.doctorPatientList,'sdfdsa')
    // this.executeMethod('patientListInfo',info)
  },

  methods: {
    // 接收父组件传递过来的数据
    async executeMethod(key, data) {
      switch (key) {
        case "patientListInfo":
          // this.$message({
          //   message: `${JSON.stringify(data)}`,
          //   type: 'success',
          //   duration: 30000
          // });
          let patientList = this.$lodash.cloneDeep(data);
          await this.$store.dispatch("setWaitDeptsPatientsInfo", patientList);
          break;
      }
    },
  },

  watch: {
    field: {
      handler: function (val) {
        this.widgetKey = uuid();
        let key = val.options.config;
        this.optionsInfo = val.options[key];
      },
      deep: true,
      immediate: true,
    },
  },

  destroyed() {
    this.unregisterFromRefList();
  },
};
</script>

<style lang="scss" scoped>
.scene-waiting-current-waiting {
  box-sizing: border-box;
  justify-content: center;
  display: flex;
  flex-wrap: nowrap;
  flex-direction: row;
  color: #333;
  height: auto;
  font-size: 50px;
  overflow: hidden;
  background: #e5eaef;

  .dept-wrp {
    width: 100%;
    height: 100%;
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;

    .dept-item {
      overflow: hidden;
      width: calc(100%);
      display: flex;
      flex-direction: row;
      justify-content: space-between;

      .dept-con {
        flex-basis: 49%;
        overflow: hidden;
      }

      .top-wrp {
        background: #203864;
        color: #ffffff;
        display: flex;
        min-width: 100%;
        padding: 0 20px;
        box-sizing: border-box;
        flex-direction: column;
        justify-content: center;
        align-items: center;

        .dept-room-name {
          width: 100%;
          text-align: center;
          display: flex;
          justify-content: center;
          overflow: hidden;
          white-space: nowrap;
        }
      }

      .ing-wrp {
        font-weight: 500;
        display: flex;
        align-items: center;
        padding: 0;

        .ing-label {
          writing-mode: vertical-rl;
          display: flex;
          width: 90px;
          min-width: 90px;
          max-width: 90px;
          justify-content: center;
          align-items: center;
          flex-shrink: 0;
          height: 100%;
        }

        .ing-con {
          overflow: hidden;
          padding: 0 20px;
          box-sizing: border-box;
          width: calc(100% - 90px);
        }
      }

      .wait-wrp {
        font-weight: 500;
        display: flex;
        align-items: center;
        padding: 0;

        .wait-label {
          writing-mode: vertical-rl;
          display: flex;
          min-width: 90px;
          width: 90px;
          max-width: 90px;
          justify-content: center;
          align-items: center;
          flex-shrink: 0;
          height: 100%;
        }

        .wait-icon {
          overflow: hidden;
          padding: 0 20px;
          height: 100%;
          box-sizing: border-box;
          width: calc(100% - 90px);
        }

        .patient-item {
          display: flex;
          height: 50%;
          align-items: center;
          overflow: hidden;
        }
      }
    }
  }

  .waiting-inside {
    min-width: calc(100% / 2 - 15px);

    &:first-child {
      box-sizing: border-box;
      margin-right: 15px;
    }

    &:last-child {
      box-sizing: border-box;
      margin-left: 15px;
    }
  }

  .dept-area {
    font-size: 76px;
    color: #ffffff;
    width: 100%;
    text-align: center;
    background: #0059b3;
    padding: 0 20px;
    height: 186px;
    line-height: 186px;
    overflow: hidden;
    border-radius: 32px 32px 0 0;
    @include singleEllipsis(100%);
  }

  .patient-area {
    box-shadow: 30px 30px 30px -10px rgba(0, 0, 0, 0.15),
      inset 5px 5px 10px rgba(255, 255, 255, 0.75),
      inset -1px -1px 10px rgba(0, 0, 0, 0.2);

    .current-area {
      margin-top: 16px;
      display: flex;
      align-items: center;
      align-self: center;
      border-radius: 12px;
      height: 160px;
      overflow: hidden;
      flex-direction: row;
      background: rgba(0, 89, 179, 1);

      .title {
        color: white;
        font-size: 40px;
        height: 100%;
        box-sizing: border-box;
        width: 260px;
        padding: 0 20px;
        background: rgba(0, 71, 143, 1);
        display: flex;
        justify-content: center;
        align-items: center;
        align-self: center;

        .scrollText {
          width: 100%;
        }
      }

      .content {
        color: white;
        display: flex;
        flex: 1;
        flex-direction: row;
        align-items: center;
        align-self: center;
        width: calc(100% - 270px);

        p {
          flex-basis: calc(100% / 1);
          font-size: 44px;
          color: white;
          text-align: center;
          padding: 0 20px;
          box-sizing: border-box;
          @include singleEllipsis(100%);
        }
      }
    }

    .waiting-area {
      display: flex;
      margin-top: 14px;
      flex-direction: column;
      border-radius: 0 0 24px 24px;
      overflow: hidden;

      .title {
        background: linear-gradient(
          rgba(244, 244, 244, 1) 0%,
          rgba(240, 240, 240, 1) 100%
        );
        text-align: center;
        font-size: 50px;
        height: 120px;
        width: 100%;
        color: #0059b3;
        border-bottom: 2px solid #dddddd;
        @include fontWeight();
        display: flex;
        padding: 0 20px;
        align-self: center;
        align-items: center;
        justify-content: center;

        .scrollText {
          width: 100%;
        }
      }

      .content {
        background: white;
        display: flex;
        flex-wrap: wrap;

        .content-inside {
          width: 100%;
          display: flex;
          padding: 8px 0;
          flex-wrap: wrap;

          .patient-item {
            flex-basis: calc(100% / 2);
            font-weight: 400;
            text-align: center;
            height: 120px;
            font-size: 54px;
            display: flex;
            align-items: center;
            align-self: center;
            justify-content: center;
            color: #333333;
            overflow: hidden;

            .patient-item-inside {
              padding: 0 24px;
              @include singleEllipsis(100%);
            }
          }
        }
      }

      .even {
        background: rgba(244, 244, 244, 1);
      }
    }
  }
}
</style>
